package reflect;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;

/**
 * @Classname: Test1
 * @Author: bromide
 * @CreateTime: 2022/4/18--11:41
 * @Version: V1.0
 * @Description: 实例化十个Person对象
 * Person对象中的name顺序为：test1--test10
 * age顺序为：21-30
 * 并存入一个集合
 */
public class Test1 {
    public static void main(String[] args) throws Exception {
        List<Person> list = new ArrayList<>();
        Class cls = Class.forName("reflect.Person");
        Constructor c = cls.getConstructor(String.class, int.class);
        for (int i = 1; i <= 10; i++) {
            String name = "test" + i;
            int age = 20 + i;
            Person person = (Person) c.newInstance(name, age);
            list.add(person);
        }
        System.out.println(list);

    }
}
